SQL by Andy Oppel

SQL by Andy Oppel

Author:Andy Oppel
Language: eng
Format: epub
Publisher: McGraw-Hill Education
Published: 2016-04-12T04:00:00+00:00


The SELECT statement produces exactly the same results as the preceding statement, only now the tables are referenced by different names, except in the FROM clause. In fact, you use the FROM clause to define the aliases that are used in the rest of the statement. In this case, the CD_INVENTORY table is renamed c, and the PERFORMERS table is renamed p. As a result, c and p must be used everywhere else in the SELECT statement when referring to those tables. Once a correlation name has been defined, you cannot use the actual table name. And yes, this can be confusing because you use the alias in the SELECT clause, but it is not defined until the FROM clause that follows the SELECT clause.

To better understand how the renaming process works, let’s revisit the issue of how SELECT statements are processed. As you might recall from Chapter 7, the FROM clause is processed first and the SELECT clause is processed last. That is why the correlation names are defined in the FROM clause. Once they are defined, all other clauses can (and must) use those aliases when qualifying column references. The correlation names are used throughout the remainder of the statement, but they only apply to the statement in which they are defined. If you create a new SELECT statement, you must redefine those names in order to use them in the new statement.

As you can see in the previous SELECT statement, a correlation name is defined immediately after the actual table name. The new name follows the AS keyword. However, the AS keyword is not required. In most implementations, you can also use the following convention to rename the tables within a query:



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.